//
//  MyTableViewCell.m
//  Boom
//
//  Created by 云鹏 赵 on 15/3/6.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "MyTableViewCell.h"

@implementation MyTableViewCell
- (void)dealloc
{
    [_singleModel release];
    [_backgroundLable release];
    [_ImageView release];
    [_albumLable release];
    [_titleLable release];
    [_likesLable release];
    [_playCountsLable release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatCell];
    }
    return self;
}
- (void)creatCell
{
    self.backgroundColor = self.backgroundColor = [UIColor colorWithRed:244 / 255.0 green:244 / 255.0 blue:244 / 255.0 alpha:1];
    
    // 创建背景backgroundLable
    self.backgroundLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, 375, 115)];
    self.backgroundLable.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.backgroundLable];
    [_backgroundLable release];
    
    // 创建图片imageView;
    self.ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 12.5, 100, 100)];
    self.ImageView.backgroundColor = [UIColor whiteColor];
    self.ImageView.layer.masksToBounds = YES;
    // 2. 设置图片圆角
    self.ImageView.layer.cornerRadius = 50;
    // 3. 设置边框宽度
    self.ImageView.layer.borderWidth = 0.5;
    // 4. 设置边框颜色
    self.ImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    [self addSubview:self.ImageView];
    [_ImageView release];
    
    // 专辑名albumLable
    self.albumLable = [[UILabel alloc] initWithFrame:CGRectMake(self.ImageView.frame.origin.x + self.ImageView.frame.size.width + 20, self.ImageView.frame.origin.y + 10, 200, 20)];
    self.albumLable.backgroundColor = [UIColor whiteColor];
    self.albumLable.font = [UIFont systemFontOfSize:16.0];
//    self.albumLable.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.albumLable];
    [_albumLable release];
    
    // 标题titleLable
    self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(self.albumLable.frame.origin.x, self.albumLable.frame.origin.y + self.albumLable.frame.size.height, 200, 50)];
    self.titleLable.backgroundColor = [UIColor whiteColor];
    self.titleLable.font = [UIFont systemFontOfSize:15.0];
    self.titleLable.textColor = [UIColor grayColor];
    self.titleLable.numberOfLines = 0;
//    self.titleLable.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.titleLable];
    [_titleLable release];
    
    // 喜欢人数likesLable
    self.likesLable = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLable.frame.origin.x + 20, self.titleLable.frame.origin.y + self.titleLable.frame.size.height, 70, 20)];
    self.likesLable.backgroundColor = [UIColor whiteColor];
    self.likesLable.font = [UIFont systemFontOfSize:13.0];
    self.likesLable.textColor = [UIColor grayColor];
    [self addSubview:self.likesLable];
    [_likesLable release];
    
    // 播放数量playCountsLable
    self.playCountsLable = [[UILabel alloc] initWithFrame:CGRectMake(self.likesLable.frame.origin.x + self.likesLable.frame.size.width + 30, self.likesLable.frame.origin.y, 70, 20)];
    self.playCountsLable.backgroundColor = [UIColor whiteColor];
    self.playCountsLable.font = [UIFont systemFontOfSize:13.0];
    self.playCountsLable.textColor = [UIColor grayColor];
    [self addSubview:self.playCountsLable];
    [_playCountsLable release];
    
    
}

// 重写set方法
-  (void)setSingleModel:(SingleModel *)singleModel
{
    if (_singleModel != singleModel) {
        [_singleModel release];
        _singleModel = [singleModel retain];
    }
    // SD 加载图片
    NSString *string = _singleModel.coverLarge;
    NSURL *url = [NSURL URLWithString:string];
    [self.ImageView sd_setImageWithURL:url placeholderImage:nil];
    
    self.albumLable.text = _singleModel.albumTitle;
    self.titleLable.text = _singleModel.title;
    self.playCountsLable.text = [NSString stringWithFormat:@"播放:%d", _singleModel.playtimes];
    self.likesLable.text = [NSString stringWithFormat:@"喜欢:%d", _singleModel.likes];
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
